package day14.itcast.web.BeanUtls;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * @author admin
 */
public class JavaBean {
    private String property;

    public JavaBean() {
    }

    public JavaBean(String property) {
        property = property;
    }

    public String getProperty() {
        return property;
    }

    public void setProperty(String property) {
        property = property;
    }

    public static void populate(Object obj, Map map) {
        Class clazz = obj.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for (Object key : map.keySet()) {
            String value = (String) map.get(key);
            try {
                Method method = clazz.getMethod("set" + key, String.class);
                method.invoke(obj, value);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
